<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
</head>

<body>
    <div id="app">
        <div>姓名:<input v-model="name"></div>
        <div>土豆:<input v-model="nickname"></div>
        <div>user的姓名:<input v-model="user.name"></div>
        <div>user的年龄:<input v-model="user.age"></div>

    </div>
</body>
<script>
    new Vue({
        el: '#app',
        data: {
            name: '张三',
            nickname: '土豆',
            user: {
                age: 18,
                name: '李四'
            }
        },
        watch: {
            nickname: {
                handler(newVal, oldVal) {
                    console.log(newVal);
                    console.log(oldVal);
                },
                immediate: true
            },
            name(newVal, oldVal) {
                console.log(newVal);
                console.log(oldVal);
            },
            user: {
                handler(newVal) {
                    console.log(newVal);
                },
                //如果 watch 监听的是一个对象，可能不能够直接进行监听 则需要你设置deep: true
                deep: true,
                immediate: true
            }
        }
    })
</script>

</html>